//
//  IndexViewModel.m
//  zhijiansuzhou
//
//  Created by 度周末网络-王腾 on 16/6/8.
//  Copyright © 2016年 Suzhou fish Information Technology Co., Ltd. All rights reserved.
//

#import "IndexViewModel.h"

@implementation IndexViewModel

-(id)init{
    
    self.bannerList = [[NSMutableArray alloc ] init];
    self.bannerStrings = [[NSMutableArray alloc ] init];
    self.sectionTopList = [[NSMutableArray alloc ] init];
    self.sectionMiddleList = [[NSMutableArray alloc ] init];
    self.sectionBottomList = [[NSMutableArray alloc ] init];
    self.noticInfoList = [[NSMutableArray alloc ] init];
    return [super init];
}

-(void)loadIndexData:(DealDataResultBlock)resultBlock{
    JGProgressHUD * hud = [utils getProcess:JGProgressHUDStyleExtraLight interaction:JGProgressHUDInteractionTypeBlockAllTouches zoom:NO dim:NO shadow:YES];
    [utils showSimpleHUD:hud showText:nil target:nil];
    
    
    __weak typeof(self) weakself = self;
    [HttpNetWorkUtil requestshortLogin:nil success:^(id json) {
        [hud dismiss];
        
        weakself.indexModel = [[InfoDataModel alloc] init];
        [weakself.indexModel fillWithJsonDict:json];
        
        NSData *data = [RFJModel toDataWithModel:weakself.indexModel];
        [utils setObject:data forkey:PERSONINFO];
        
        // 配置区域参数
        [weakself configSectionList];
        
        resultBlock(1,nil,nil,nil);
    } fail:^{
        [hud dismiss];
        resultBlock(0,nil,nil,nil);
    }];
}

-(void)configSectionList{
    
    [self.sectionTopList removeAllObjects];
    [self.sectionBottomList removeAllObjects];
    
    for (moduleListInfoModel *moduleModel in self.indexModel.infomodel.moduleList) {
        if ([moduleModel.menuType isEqualToString:@"1"]) {
            [self.sectionTopList addObject:moduleModel];
        }else if ([moduleModel.menuType isEqualToString:@"3"]){
            [self.sectionBottomList addObject:moduleModel];
        }
    }
    
    [self.sectionTopList addObjectsFromArray:[self.indexModel.infomodel.moduleList subarrayWithRange:NSMakeRange(0, 8)]];
    
    [self.sectionBottomList addObjectsFromArray:[self.indexModel.infomodel.moduleList subarrayWithRange:NSMakeRange(8, self.indexModel.infomodel.moduleList.count-8)]];
    
    
    // 解析广告数据
    [self.sectionMiddleList removeAllObjects];
    [self.bannerList removeAllObjects];
    [self.bannerStrings removeAllObjects];
    
    for (advListInfoModel *advModel in self.indexModel.infomodel.advList) {
        if ([advModel.advId isEqualToString:@"1"]) {
            [self.bannerList addObject:advModel];
            [self.bannerStrings addObject:advModel.imgPath];
        }else if ([advModel.advId isEqualToString:@"2"]){
            
            // 列表中的数据
            [self.sectionMiddleList addObject:advModel];
        }
    }
    
    // 消息栏数据
    [self.noticInfoList removeAllObjects];
    for (noticInfoModel *noticModel in self.indexModel.infomodel.noticeBoardList) {
        [self.noticInfoList addObject:noticModel.messageContent];
    }
}

@end
